#include<iostream>
using std::endl;
using std::cout;
using std::cin;
//需要单例实现的类
class SignalItem{
public:
    static SignalItem *  getInstent(){
        if(!_si){
           _si = new SignalItem(98);
        }
        return _si;
    }
    void print(){
        cout<<"!!!"<<_num<<endl;
    }
    void inti(int num){
        _num = num;
    }
    /*static void destroy(){
        if(_si){
            delete _si;
            _si = nullptr;
        }
    }*/
     SignalItem(const SignalItem&) = delete;
     SignalItem& operator=(const SignalItem&)=delete;
    //关键 能访问私有的析构函数的关键
    friend class  AutoRelease ;
private:

    SignalItem(int x)
        :_num(x){
            cout<<"SI"<<endl;
        }
        ~SignalItem(){
            cout<<"~SignalItem"<<endl;          
        }
    int _num;
    static SignalItem *_si;
};
SignalItem* SignalItem::_si = nullptr;
class AutoRelease{
public:
    AutoRelease(SignalItem*si)
        :_sig(si){
            cout<<"Auto"<<endl;
    }
    ~AutoRelease(){
        if(_sig){
            delete _sig;
            _sig=nullptr;
            cout<<"~AUTO"<<endl;
        }
    }
private:
    SignalItem *_sig;
};

void test1(){
    AutoRelease ar(SignalItem::getInstent());
    cout<<SignalItem::getInstent()<<endl;
    SignalItem::getInstent()->inti(23);
    cout<<SignalItem::getInstent()<<endl;
    SignalItem::getInstent()->print();
    cout<<SignalItem::getInstent()<<endl;
    
}
int main(){
    test1();
    return 0;
}
